package com.wavehi.web;

import com.wavehi.pojo.User;
import com.wavehi.service.UserService;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @Author WaveHi
 * @Date 17/9/2021 下午 3:40
 * @Version 1.0
 * @Contact HJBWaveHi@163.com
 * @Description Deal the request of user
 */
@WebServlet("/userServlet")
public class UserServlet extends BaseServlet{

    protected void base(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }
    protected void list(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取所有用户信息
        UserService uService = new UserService();
        List<User> users = uService.list();
        //将用户信息设置到请求域中
//        List<User> users = new ArrayList<>(16);
//        users.add(new User(1L, "qewp", "132"));
        req.setAttribute("users", users);
        //获取请求转发对象
        RequestDispatcher requestDispatcher = req.getRequestDispatcher("/page/admin/user_display.jsp");
        //转发
        requestDispatcher.forward(req, resp);
    }
}
